<template>
  <div class="details-container app-container" v-loading="listLoading">
    <div class="detail-title">
      <div>用户基础信息</div>
      <el-button type="primary" size="small" @click="changeUserInfo">修改</el-button>
    </div>
    <div class="detail-content">
      <el-row :gutter="80">
        <el-col :span="12">
          <div class="left-text">用户名称:</div>
          <div><el-input v-model="userDetail.nick_name" /></div>
        </el-col>
        <el-col :span="12">
          <div class="left-text">用户ID: </div>
          <div>{{ userDetail.id_public_user_info }}</div>
        </el-col>
      </el-row>
      <el-row :gutter="80">
        <el-col :span="12">
          <div class="left-text">所属门店:</div>
          <div>{{ userDetail.agent_name }}</div>
        </el-col>
        <el-col :span="12">
          <div class="left-text">用户类型: </div>
          <div>
            <el-radio-group v-model="userDetail.user_type">
              <el-radio :label="0">普通员工</el-radio>
              <el-radio :label="111">普通店员</el-radio>
              <el-radio :label="112">店长</el-radio>
              <el-radio :label="113">运营总监</el-radio>
            </el-radio-group>
          </div>
        </el-col>
      </el-row>
      <el-row :gutter="80">
        <el-col :span="12">
          <div class="left-text">性别:</div>
          <div>{{ userDetail.user_sex === 1 ? '男' : (userDetail.user_sex === 2 ? '女' : '不详') }}</div>
        </el-col>
        <el-col :span="12">
          <div class="left-text">注册时间: </div>
          <div>{{ userDetail.time_register }}</div>
        </el-col>
      </el-row>
      <el-row :gutter="80">
        <el-col :span="12">
          <div class="left-text">手机号:</div>
          <div><el-input v-model="userDetail.user_phone" /></div>
        </el-col>
        <el-col :span="12">
          <div class="left-text">地址: </div>
          <div>{{ userDetail.add_desc || '-' }}</div>
        </el-col>
      </el-row>
      <el-row :gutter="80">
        <el-col :span="12">
          <div class="left-text">最后消费时间:</div>
          <div>{{ userDetail.time_update }}</div>
        </el-col>
        <el-col :span="12">
          <div class="left-text">最后登录时间: </div>
          <div>{{ userDetail.login_time }}</div>
        </el-col>
      </el-row>
      <el-row :gutter="80">
        <el-col :span="12">
          <div class="left-text">修改密码:</div>
          <div><el-input v-model="password" /></div>
        </el-col>
      </el-row>
    </div>
    <div class="other-content">
      <div class="item-content">
        <div>
          <div>账户余额</div>
          <div class="number-text">{{ otherInfo.left_money }}元</div>
        </div>
        <div><el-button>查看详情</el-button></div>
      </div>
      <div class="item-content">
        <div>
          <div>积分余额</div>
          <div class="number-text">{{ otherInfo.left_score }}元</div>
        </div>
        <div><el-button>查看详情</el-button></div>
      </div>
    </div>
  </div>
</template>

<script>
import waves from '@/directive/waves' // waves directive
import { orderList } from '@/api/order'
export default {
  name: 'UserDetails',
  directives: { waves },
  data() {
    return {
      listLoading: true,
      userDetail: {},
      otherInfo: {},
      password: '',
      detailQuery: {
        invoke_method: 'public_page_4m_user_4_balance',
        buyer_id: null
      },
      changeQuery: {
        invoke_method: 'change_user_info',
        nick_name: null,
        user_phone: null,
        user_type: null,
        pre_db_para_id_public_user_info: null,
        password_user: null
      }
    }
  },
  mounted() {
    this.detailQuery.buyer_id = this.$route.query.user_id
    this.changeQuery.pre_db_para_id_public_user_info = this.$route.query.user_id
    this.getList()
  },
  methods: {
    /*
    * 获取页面数据
    * */
    getList() {
      this.listLoading = true
      orderList(this.Qs.stringify(this.detailQuery)).then(response => {
        console.log(response)
        this.userDetail = response.public_user_info
        this.otherInfo = response

        // Just to simulate the time of the request
        setTimeout(() => {
          this.listLoading = false
        }, 0.5 * 1000)
      })
    },
    /*
    * 修改用户信息
    * */
    changeUserInfo() {
      this.changeQuery.nick_name = this.userDetail.nick_name
      this.changeQuery.user_phone = this.userDetail.user_phone
      this.changeQuery.id_public_user_info = this.userDetail.id_public_user_info
      this.changeQuery.password_user = this.password
      this.changeQuery.user_type = this.userDetail.user_type
      orderList(this.Qs.stringify(this.changeQuery)).then(res => {
        this.$notify({
          title: 'Success',
          message: '修改成功',
          type: 'success',
          duration: 2000
        })
        this.getList()
      })
    }
  }
}
</script>

<style lang="scss" scoped>
@import "../../styles/variables";

.detail-title {
  border-bottom: 1px solid #e3e3e3;
  padding: 16px 0;
  font-size: 16px;
  font-weight: bold;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.detail-content {
  padding: 24px 24px 0;
  .el-row {
    margin-bottom: 36px;
    font-size: 14px;
    display: flex;

    .el-col {
      display: flex;
      justify-content: space-between;
      align-items: flex-end;
      .left-text {
        color: #2d2f33;
      }
      .el-input {
        ::v-deep {
          .el-input__inner {
            border-radius: 0;
            border: none;
            border-bottom: 1px solid $tiffany;
            padding-left: 0;
            text-align: right;
          }
        }
      }
    }
  }
}

.other-content {
  .item-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 24px;
    border: 1px solid #e3e3e3;
    border-bottom: none;
    &:last-child {
      border-bottom: 1px solid #e3e3e3;
    }

    .number-text {
      color: #409EFF;
      font-weight: bold;
      margin-top: 12px;
    }

    .el-button {
      background-color: transparent;
      border: none;
      color: #409EFF;
    }
  }
}
</style>
